package com.taokatao.cardmee.business.profile;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.taokatao.cardmee.App;
import com.taokatao.cardmee.BaseActivity;
import com.taokatao.cardmee.C;
import com.taokatao.cardmee.R;
import com.taokatao.cardmee.Utils;
import com.taokatao.cardmee.WebActivity;
import com.taokatao.cardmee.common.widget.TitleLayout;

import butterknife.BindView;
import butterknife.ButterKnife;


public class ProfileAboutActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.l_title) TitleLayout layTitle;

    @BindView(R.id.t_version) TextView tVersion;
    @BindView(R.id.l_rules) View lRules;
    @BindView(R.id.l_rate) View lRate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_about);
        ButterKnife.bind(this);

        String versionInfo = getString(R.string.app_name) + " V" + Utils.getAppVersionName();
        if (App.DEBUG_SERVICE) versionInfo += " .Test";
        if (App.DEBUG_LOG) versionInfo += " .Log";
        tVersion.setText(versionInfo);

        Utils.throttleFirstClick(lRules, this);
        Utils.throttleFirstClick(lRate, this);
    }

    @Override
    public void onClick(View v) {
        if (v == lRules) {
            Utils.onMobEvent(this, "clickUserProtocolOfAbout");
            Intent intent = new Intent(this, WebActivity.class);
            intent.putExtra("extra_title", "用户使用协议");
            intent.putExtra("extra_is_fixed_title", true);
            intent.putExtra("extra_url", C.http.RELEASE_SERVICE_URL_RULES);
            startActivity(intent);
        } else if (v == lRate) {
            Utils.onMobEvent(this, "clickPraiseOfAbout");
            try {
                Uri uri = Uri.parse("market://details?id=" + getPackageName());
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
                Utils.logd("ProfileAboutActivity Couldn't launch the market !");
                Intent intent = new Intent(this, WebActivity.class);
                intent.putExtra("extra_url", C.http.APP_RATE_URL);
                startActivity(intent);
            }
        }
    }
}
